package com.dkd.easybook.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dkd.common.annotation.Log;
import com.dkd.common.core.controller.BaseController;
import com.dkd.common.core.domain.AjaxResult;
import com.dkd.common.enums.BusinessType;
import com.dkd.easybook.domain.EbAttachmentRelations;
import com.dkd.easybook.service.IEbAttachmentRelationsService;
import com.dkd.common.utils.poi.ExcelUtil;
import com.dkd.common.core.page.TableDataInfo;

/**
 * 附件关系Controller
 *
 * @author itheima
 * @date 2024-12-30
 */
@Api(tags = "附件关系Controller")
@RestController
@RequestMapping("/easybook/attachmentRelations")
public class EbAttachmentRelationsController extends BaseController
{
    @Autowired
    private IEbAttachmentRelationsService ebAttachmentRelationsService;

    /**
     * 查询附件关系列表
     */
    @ApiOperation("查询附件关系列表")
    @PreAuthorize("@ss.hasPermi('easybook:attachmentRelations:list')")
    @GetMapping("/list")
    public TableDataInfo list(EbAttachmentRelations ebAttachmentRelations)
    {
        startPage();
        List<EbAttachmentRelations> list = ebAttachmentRelationsService.selectEbAttachmentRelationsList(ebAttachmentRelations);
        return getDataTable(list);
    }

    /**
     * 导出附件关系列表
     */
    @ApiOperation("导出附件关系列表")
    @PreAuthorize("@ss.hasPermi('easybook:attachmentRelations:export')")
    @Log(title = "附件关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EbAttachmentRelations ebAttachmentRelations)
    {
        List<EbAttachmentRelations> list = ebAttachmentRelationsService.selectEbAttachmentRelationsList(ebAttachmentRelations);
        ExcelUtil<EbAttachmentRelations> util = new ExcelUtil<EbAttachmentRelations>(EbAttachmentRelations.class);
        util.exportExcel(response, list, "附件关系数据");
    }

    /**
     * 获取附件关系详细信息
     */
    @ApiOperation("获取附件关系详细信息")
    @PreAuthorize("@ss.hasPermi('easybook:attachmentRelations:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ebAttachmentRelationsService.selectEbAttachmentRelationsById(id));
    }

    /**
     * 新增附件关系
     */
    @ApiOperation("新增附件关系")
    @PreAuthorize("@ss.hasPermi('easybook:attachmentRelations:add')")
    @Log(title = "附件关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EbAttachmentRelations ebAttachmentRelations)
    {
        return toAjax(ebAttachmentRelationsService.insertEbAttachmentRelations(ebAttachmentRelations));
    }

    /**
     * 修改附件关系
     */
    @ApiOperation("修改附件关系")
    @PreAuthorize("@ss.hasPermi('easybook:attachmentRelations:edit')")
    @Log(title = "附件关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EbAttachmentRelations ebAttachmentRelations)
    {
        return toAjax(ebAttachmentRelationsService.updateEbAttachmentRelations(ebAttachmentRelations));
    }

    /**
     * 删除附件关系
     */
    @ApiOperation("删除改附件关系")
    @PreAuthorize("@ss.hasPermi('easybook:attachmentRelations:remove')")
    @Log(title = "附件关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ebAttachmentRelationsService.deleteEbAttachmentRelationsByIds(ids));
    }
}
